﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using Controllers;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Web
{
    public partial class Contact : System.Web.UI.Page
    {
        protected string noAuthed = "noAuthed";
        protected void Page_Load(object sender, EventArgs e)
        {
            EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            Database db = DatabaseFactory.CreateDatabase();
            string strSql = @"with t as (select Id,Pid,Text,OrderNo,cast(OrderNo as nvarchar(50)) orderStr from Depts where Pid is null
union all
select d.Id,d.Pid,d.Text,d.OrderNo,cast(t.orderStr+cast(d.OrderNo as nvarchar(50)) as nvarchar(50))
from Depts d,t where d.Pid=t.id and IsValid=1
)
 SELECT a.Id,a.Name,t.Id DeptId,t.Pid DeptPid,t.Text Dep,
 TelExt,Mobile,ShortNo
  FROM Employee a,EmpDepPositions b,t,Positions d
  where a.LeaveDate is null and a.Id=b.EmpId and b.DeptId=t.Id and b.PosId=d.Id
  order by t.orderStr,b.DeptId,d.Id,a.Id;";
            DataSet ds =db.ExecuteDataSet(CommandType.Text,strSql);

            rptList.DataSource = ds.Tables[0];
            rptList.DataBind();
            if (ebi.EmpRoles.Where(r => r.RoleId == 1).Any())//超级管理员角色
            {
                noAuthed = "";
            }
        }

        protected string getMobile(object mobileObj,object deptIdObj)
        {
            string mobileNo = "";
            if (mobileObj != null)
            {
                EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
                IList<int> deptIds = Session["deptIdList"] as List<int>;
                int deptId = int.Parse(deptIdObj.ToString());
                if (deptIds.Contains(deptId) || ebi.EmpRoles.Where(r => r.RoleId == 1).Any() || ebi.EmpDepPos.First().DeptId == deptId)
                {
                    mobileNo = mobileObj.ToString();
                }
            }
            return mobileNo;
        }
    }
}